package com.spider.util;

import com.alibaba.fastjson.JSONObject;
import com.spider.constant.FangYHLUrl;
import com.spider.entity.YjsPriceEntity;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.LinkedHashMap;

public class FangYHLUtil {

    /**
     * 动态拼接body
     * @return
     */
    public static JSONObject getUpdatePrice(YjsPriceEntity entity){
        JSONObject body=new JSONObject(new LinkedHashMap());
        if(entity.getPrice()==null){
            return null;
        }
        BigDecimal base=entity.getPrice();
        BigDecimal discount=BigDecimal.ZERO;
        body.put("vipCode",FangYHLUrl.vipCode);
        body.put("appSecurity",FangYHLUrl.appSecurity);
        body.put("version", FangYHLUrl.version);
        if(entity.getCxbs()!=null&&entity.getCxbs().equals("不打折")){
            discount=base;

        }else{
            discount=base.multiply(new BigDecimal(0.85).setScale(2, BigDecimal.ROUND_HALF_UP));
        }
        String gg=StringUtil.substringNum(entity.getNum())+entity.getUnit();
        body.put("price",discount);
        body.put("brand",entity.getBrand());
        body.put("itemNum",entity.getHs());
        body.put("packingSpecification",gg);
        //开始时间设为今天，结束时间设置为明年
        LocalDateTime now =LocalDateTime.now();
        body.put("startTime",now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS")));
        body.put("endTime",now.plusYears(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS")));
        return body;
    }

    /**
     * 动态拼接body
     * @return
     */
    public static JSONObject getUpdatePriceTest(){
        JSONObject body=new JSONObject(new LinkedHashMap());
        body.put("vipCode",FangYHLUrl.vipCode);
        body.put("appSecurity",FangYHLUrl.appSecurity);
        body.put("price","1449");
        body.put("brand","希恩思");
        body.put("itemNum","E-96080");
        body.put("packingSpecification","100g");
        //开始时间设为今天，结束时间设置为明年
        LocalDateTime now =LocalDateTime.now();
        body.put("startTime",now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS")));
        body.put("endTime",now.plusYears(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS")));
        return body;
    }


}
